define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var newImg;
    var clientH=$(window).height();
    var clientW=$(window).width();
    var w = '250';
    var h = '250';
    $(document).ready(function(){
        $(".comment_pics").bind("click", function(){
            newImg = $(this)[0].src;
            $("body").append('<div class="fillbg"></div>');
            $(".fillbg").addClass("fillbg-active");
            $('.bgImg').css({'width': w+"px",'height': h+"px",'top':(clientH-h)/2+"px",'left':(clientW-w)/2+"px",'z-index':1101});
            $('.bgImg').attr("src",newImg);
        });

        $(".bgImg").bind("click", function(){
            $(".fill-input").removeClass("fill-input-active");
            setTimeout(function(){
                $(".fillbg-active").removeClass("fillbg-active");
                $(".fillbg").remove();
            },300);
            $('.bgImg').css({'width': '0px','height': '0px'});
            $('.bgImg').attr("src",'');
        });


        $(".b1").bind("click", function(){
            var id=$("input[name='return_id']").val();
            var sjtkprice=$("input[name='sjtkprice']").val();
            if (confirm('确认要同意退款吗?同意之后操作不能更改，金额会原路返回')) {
                $.post("orderdetail/agressdNew",{id:id,sjtkprice:sjtkprice},function(data,status){
                    if(data.code==1)
                    {
                        alert("操作成功");
                        location.reload();
                    }
                    else
                    {
                        alert(data.msg);
                    }
                });
            } else {
                return false;
            }
        });

        $(".b2").bind("click", function(){
            var id=$("input[name='return_id']").val();
            var service_break=$("input[name='service_break']").val();
            $.post("orderdetail/refundNew",{id:id,service_break:service_break},function(data,status){
                if(data.code==1)
                {
                    alert("操作成功");
                    location.reload();
                }
                else
                {
                    alert(data.msg);
                }
            });
        });


        $(".b3").bind("click", function(){
            var id=$("input[name='return_id']").val();
            $.post("orderdetail/agressdNewHAM",{id:id},function(data,status){
                if(data.code==1)
                {
                    alert("操作成功");
                    location.reload();
                }
                else
                {
                    alert(data.msg);
                }
            });
        });



    });



    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'orderdetail/index' + location.search,
                    add_url: 'orderdetail/add',
                    // edit_url: 'orderdetail/edit',
                    // del_url: 'orderdetail/del',
                    multi_url: 'orderdetail/multi',
                    import_url: 'orderdetail/import',
                    table: 'orderdetail',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        // {field: 'order_id', title: __('Order_id')},
                        // {field: 'userhome_id', title: __('Userhome_id')},
                        // {field: 'goods_id', title: __('Goods_id')},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'goods_spec_name', title: __('Goods_spec_name'), operate: 'LIKE'},
                        {field: 'num', title: __('Num')},
                        {field: 'price', title: __('Price'), operate:false},
                        {field: 'leave', title: __('Leave')},
                        {field: 'evaluate', title: __('Evaluate'), operate: 'LIKE'},
                        {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'pjtime', title: __('Pjtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'is_pingjia', title: __('Is_pingjia'), searchList: {"0":__('Is_pingjia 0'),"1":__('Is_pingjia 1')}, formatter: Table.api.formatter.normal},
                        {field: 'tkyy', title: __('Tkyy'), operate: 'LIKE'},
                        {field: 'thnum', title: __('Thnum')},
                        {field: 'tkprice', title: __('Tkprice'), operate:false},
                        {field: 'remark', title: __('Remark'), operate: 'LIKE'},
                        {field: 'shhimages', title: __('Shhimages'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'shouhoutime', title: __('Shouhoutime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'is_shouhou', title: __('Is_shouhou'), searchList: {"0":__('Is_shouhou 0'),"1":__('Is_shouhou 1'),"2":__('Is_shouhou 2'),"3":__('Is_shouhou 3')}, formatter: Table.api.formatter.normal},
                        {field: 'id', title: __('查看售后详情'), formatter: Controller.api.formatter.id,operate:false},
                    ]
                ],
                search:false,
                showColumns: false,
                showToggle: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                id: function (value, row, index) {
                    //这里手动构造URL
                    var ids = row['id'];
                    // var store_id = row['store_id'];
                    if(row.is_shouhou == '0'){
                        return  "";
                    }
                    url = "orderdetail/shouhounew?orderdetail_id=" + ids;
                    //方式一,直接返回class带有addtabsit的链接,这可以方便自定义显示内容
                    return '<a href="' + url + '" class="label label-success addtabsit" title="' + __("查看订单详情", value) + '">' + '查看售后详情' + '</a>';


                }
            }
        }
    };
    return Controller;
});